import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect:"/home"
  },
  {
    path: '/home',
    name:"home",
    component:HomeView,
   
  },
  {
    path:'/Vip',
    name:'Vip',
    meta: {
      requireAuth: true
    },
    component: resolve => require(['../views/VipView.vue'], resolve)
 
  },{
    path:'/bookshelf',
    name:'bookshelf',
    meta: {
      requireAuth: true
    },
    component: resolve => require(['../views/bookshelf.vue'], resolve)
 
  },
   {
    path:'/BookContent',
    name:'BookContent',
       meta: {
      requireAuth: true
    },
    component: resolve => require(['../views/BookContent.vue'], resolve)
    
   
   
  },
  {
    path:'/Book',
    name:'Book',
   
  
    component:()=>import("../views/directory.vue")
  },
  {
    path:'/my',
    name:'my',
    meta: {
      requireAuth: true
    },
    component: resolve => require(['../views/my.vue'], resolve)
    
   
    
  
  },
  {
    path:'/list',
    name:'list',
    meta: {
      requireAuth: true
    },
    component: resolve => require(['../views/list.vue'], resolve)
    
   
    
  
  },
  {
    path:'/history',
    name:'history',
    meta: {
      requireAuth: true
    },
    component: resolve => require(['../views/history.vue'], resolve)
    
   
    
  
  },
  {
    path:'/new',
    name:'new',
    component:()=>import("../views/new.vue")
  },
  {
    path:'/read',
    name:'read',
    component:()=>import("../views/Reading.vue")
  },
  {
    path:'/comment',
    name:'comment',
    meta: {
      requireAuth: true
    },
    component: resolve => require(['../views/comment.vue'], resolve)
  },
  {
    path:'/login',
    name:'login',
    component:()=>import("../views/login.vue")
  }, {
    path:'/img',
    name:'img',
    component:()=>import("../views/img.vue")
  },
  {
    path:'/seru',
    name:'seru',
    component:()=>import("../views/seru.vue")
  },{
    path:'/search',
    name:'search',
    component:()=>import("../views/search.vue")
  },
  
]
// 注意:解决路由跳转问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location){
  return originalPush.call(this,location).catch(err=>err);
}







const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to, from, next) => {    
  // chrome
  document.body.scrollTop = 0
  // firefox
  document.documentElement.scrollTop = 0
  // safari
  window.pageYOffset = 0
  next()
})




export default router
